package pers.qianyu.month_202101.date_20210131;

import org.junit.*;

import java.util.*;

/**
 * 第 226 场周赛 第 3 题
 * 5667. 你能在你最喜欢的那天吃到你最喜欢的糖果吗？
 * https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day/
 *
 * @author mizzle rain
 * @date 2021年1月31日15:22:58
 */
public class CanEat {
    // 区间交集 + 整数溢出
    public boolean[] canEat(int[] candiesCount, int[][] queries) {
        int len = queries.length;
        long[] pre = new long[candiesCount.length + 1];
        for (int i = 0; i < candiesCount.length; i++) pre[i + 1] = candiesCount[i] + pre[i];
        boolean[] ans = new boolean[len];
        for (int i = 0; i < queries.length; i++) {
            int[] query = queries[i];
            int cap = query[2], day = query[1], type = query[0];
            long left = pre[type] + 1, right = pre[type + 1];
            long min = day + 1, max = (long) (day + 1) * cap;
            if (!(max < left || right < min)) {
                ans[i] = true;
            }
        }
        return ans;
    }

    @Test
    public void test1() {
        boolean[] result = new CanEat().canEat(new int[]{7, 4, 5, 3, 8},
                new int[][]{{0, 2, 2}, {4, 2, 4}, {2, 13, 1000000000}});
        System.out.println("result = " + Arrays.toString(result));
    }
}